package com.yunqi.system.models;

import com.yunqi.starter.database.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;

/**
 * 系统角色
 * Created by @author CHQ on 2022/6/15
 */
@Data
@Table("ims_sys_role")
@TableMeta("{'mysql-charset':'utf8mb4'}")
public class SysRole extends BaseModel implements Serializable{

    private static final long serialVersionUID = 1L;

    @Name
    @Column
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @Prev(els = {@EL("uuid()")})
    private String id;

    @NotBlank(message = "角色名称不能为空")
    @Column
    @Comment("角色名称")
    @ColDefine(type = ColType.VARCHAR, width = 50)
    private String name;

    @NotBlank(message = "角色标识不能为空")
    @Column
    @Comment("角色标识")
    @ColDefine(type = ColType.VARCHAR, width = 250)
    private String code;

    @Column
    @Comment("排序字段")
    @ColDefine(type = ColType.INT)
    private int sort;

    @Column
    @Comment("状态 0、禁用; 1、正常;")
    @ColDefine(type = ColType.INT)
    private int status;


    @Column
    @Comment("备注")
    @ColDefine(type = ColType.VARCHAR, width = 250)
    private String note;

    /**
     * 关联权限
     */
    @ManyMany(from = "roleId", relation = "ims_sys_role_menu", to = "menuId")
    protected List<SysMenu> menus;

    /**
     * 关联用户
     */
    @ManyMany(from = "roleId", relation = "ims_sys_user_role", to = "userId")
    private List<SysUser> users;


}
